import shop from '../../common/api/shop';
import { PRODUCTS } from '../mutation-types';
const state = {
  all: [],
  itemF: 'haha' 
}

const getters = {}

const actions = {
  getAllProducts ({commit}) {
    shop.getProducts(products => commit(PRODUCTS.SET_PRODUCTS, products) )
  }
}

const mutations = {
  [PRODUCTS.SET_PRODUCTS] (state, products) {
    state.all = products
  },

  [PRODUCTS.DECREMENT_PRODUCT_INVENTORY] (state, { id }) {
    const product = state.all.find(product => product.id === id)
    product.inventory --
  },

  [PRODUCTS.CHANGE_ITEMF] (state, data) {
    state.itemF = data
  }
}


export default {
  namespaced: true,
  state,
  getters,
  actions,
  mutations
}
